<script setup lang="ts">
import FolderPickerInput from "@/components/framework/folder-picker-input.vue";
import { reactive } from "vue";
import { useSettingStore } from "@/store/setting-store.ts";
import SettingsSection from "@/components/settings/settings-section.vue";

const settings = useSettingStore();

const formState = reactive({
  downloadDir: "",
  devInstallPath: "",
  databaseInstallPath: "",
  deleteInstallPackage: false,
  pgDeletePgAdmin: true,
});

const setDefaultValue = () => {
  formState.downloadDir = settings.downloadDir;
  formState.devInstallPath = settings.devInstallPath;
  formState.databaseInstallPath = settings.databaseInstallPath;
  formState.deleteInstallPackage = settings.deletePackageAfterInstall;
  formState.pgDeletePgAdmin = settings.pgDeletePgAdmin;
};

const saveValue = () => {
  settings.downloadDir = formState.downloadDir;
  settings.devInstallPath = formState.devInstallPath;
  settings.databaseInstallPath = formState.databaseInstallPath;
  settings.deletePackageAfterInstall = formState.deleteInstallPackage;
  settings.pgDeletePgAdmin = formState.pgDeletePgAdmin;
};
</script>

<template>
  <settings-section :model="formState" :set-default-value="setDefaultValue" :save-value="saveValue">
    <a-form-item name="downloadDir" label="下载保存路径" required>
      <folder-picker-input v-model:value="formState.downloadDir" />
    </a-form-item>
    <a-form-item
      name="devInstallPath"
      label="语言/工具安装路径"
      required
      help="注意：修改后所有已安装的工具需要手动迁移或重新安装"
      extra="环境变量需要重新设置"
    >
      <folder-picker-input v-model:value="formState.devInstallPath" />
    </a-form-item>
    <a-form-item name="databaseInstallPath" label="数据库安装路径" required help="注意：同上">
      <folder-picker-input v-model:value="formState.databaseInstallPath" />
    </a-form-item>

    <a-form-item name="deleteInstallPackage" label=" " :colon="false">
      <a-checkbox v-model:checked="formState.deleteInstallPackage">安装后删除安装包</a-checkbox>
    </a-form-item>

    <a-form-item name="pgDeletePgAdmin" label="PostgreSQL">
      <a-checkbox v-model:checked="formState.pgDeletePgAdmin">安装后删除pgAdmin</a-checkbox>
    </a-form-item>
  </settings-section>
</template>
